#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAXN 5005

int N;

struct Node {
    int L, R, I;
    Node(int l, int r, int i):L(l), R(r), I(i) { }
};

bool Node_cmp(Node & lhs, Node & rhs) {
    if (lhs.R == rhs.R) {
        return (lhs.L > rhs.L);
    }
    return (lhs.R < rhs.R);
}

vector<Node> NW, NH;
int INDW[MAXN];
int INDH[MAXN];
bool BOOKW[MAXN];

bool solve(vector<Node> & V, int * IND, bool * BOOK) {
    sort(V.begin(), V.end(), Node_cmp);
    memset(IND, 0, sizeof(int) * MAXN);
    memset(BOOK, 0, sizeof(bool) * MAXN);
    int index;
    for (int i=0; i<V.size(); i++) {
        Node & n = V[i];
        index = n.L;
        while (BOOK[index]) {
            index++;
        }
        if (index > n.R) return false;
        BOOK[index] = true;
        IND[n.I] = index;
    }
    return true;
}

int main()
{
    while (scanf("%d", &N), N) {
        NW.clear();
        NH.clear();
        for (int i=0; i<N; i++) {
            int xl, yl, xr, yr;
            scanf("%d%d%d%d", &xl, &yl, &xr, &yr);
            NW.push_back(Node(xl, xr, i));
            NH.push_back(Node(yl, yr, i));
        }
        bool ok = solve(NW, INDW, BOOKW);
        if (!ok) {
            printf("IMPOSSIBLE\n");
            continue;
        }
        ok = solve(NH, INDH, BOOKW);
        if (!ok) {
            printf("IMPOSSIBLE\n");
            continue;
        }
        for (int i=0; i<N; i++) {
            printf("%d %d\n", INDW[i], INDH[i]);
        }
    }
    return 0;
}
